package com.mop.sg2.map;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import android.content.res.Resources;

import com.mop.sg2.R;

public class TestMap {
	public static Map<String, ImageBean> maps = new ConcurrentHashMap<String, ImageBean>();

	public static void initTestMap(Resources r) throws IOException {
		String dataMap = readMap(r);
		initMap(r, dataMap);
	}

	private static String readMap(Resources r) throws IOException {
		InputStream in = r.openRawResource(R.raw.testmap);
		ByteArrayOutputStream dos = new ByteArrayOutputStream();
		byte[] data = new byte[1024];
		int length=0;
		while ((length=in.read(data)) != -1) {
			dos.write(data, 0, length);
			data = new byte[1024];
		}

		String dataMap = new String(dos.toByteArray());
		return dataMap;
	}

	private static void initMap(Resources r, String dataMap) {
		String[] imgs = dataMap.split("\n");
		String[] tmp;
		ImageBean imageBean = null;
		for (int i = 0; i < imgs.length; i++) {
			tmp = imgs[i].split("\\|");
			imageBean = new ImageBean();
			imageBean.initMap(r, tmp);
			maps.put(imageBean.getName(), imageBean);
		}
	}

	private static  void showMap(){
		
	}
}
